<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../js/jquery.js"></script>
  <script type="text/javascript" src="../../js/api.js"></script>
  <script type="text/javascript" src="../../js/axios.js"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>仓库管理</li>
    <li>仓库管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post" id="fo">
    <ul class="tools">
      <li>仓库名称:
        <input type="text" name="wareName" id="warveName"/>
      </li>
      <li> 所属区域：
        <select name="provinceName" id="provinceName">
          <option value="0">请选择省份</option>
          <option value="1">北京</option>
          <option value="2">江苏</option>
          <option value="3">天津</option>
        </select>
        <select name="cityName" id="cityName">
          <option value="0">请选择城市</option>
          <option value="1">北京</option>
          <option value="2">南京</option>
          <option value="3">天津</option>
        </select>
      </li>
      <li class="subBut" onclick="load(1,5)"><img src="../../images/t06.png" />查询</li>
      <li class="subBut" onclick="window.location.href='storageAdd.html'"><img src="../../images/t01.png" />添加</li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>仓库名称</th>
          <th>负责人</th>
          <th>联系电话</th>
          <th>所属区域</th>
          <th>状态</th>
          <th>创建时间</th>
          <th>创建人</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody id="body">
<!--        <tr>-->
<!--          <td>1</td>-->
<!--          <td>南京21号仓库</td>-->
<!--          <td>朱元璋</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>江苏南京</td>-->
<!--          <td>可用</td>-->
<!--          <td>2013-09-09 15:05:05</td>-->
<!--          <td>马云</td>-->
<!--          <td>-->
<!--          	<a href="storageView.html" class="tablelink">查看详情</a>-->
<!--            <a href="storageUpdate.html" class="tablelink">修改</a>-->
<!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认注销此条信息？')">注销</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td>2</td>-->
<!--          <td>武汉71号仓库</td>-->
<!--          <td>周瑜</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>湖北武汉</td>-->
<!--          <td>不可用</td>-->
<!--          <td>2013-09-09 15:05:05</td>-->
<!--          <td>马化腾</td>-->
<!--          <td>-->
<!--          	<a href="storageView.html" class="tablelink">查看详情</a>-->
<!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认恢复此条信息？')">恢复</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td>3</td>-->
<!--          <td>南京21号仓库</td>-->
<!--          <td>朱元璋</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>江苏南京</td>-->
<!--          <td>可用</td>-->
<!--          <td>2013-09-09 15:05:05</td>-->
<!--          <td>马云</td>-->
<!--          <td>-->
<!--          	<a href="storageView.html" class="tablelink">查看详情</a>-->
<!--            <a href="storageUpdate.html" class="tablelink">修改</a>-->
<!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认注销此条信息？')">注销</a>-->
<!--          </td>-->
<!--        </tr>-->
<!--        <tr>-->
<!--          <td>4</td>-->
<!--          <td>武汉71号仓库</td>-->
<!--          <td>周瑜</td>-->
<!--          <td>17370899727</td>-->
<!--          <td>湖北武汉</td>-->
<!--          <td>不可用</td>-->
<!--          <td>2013-09-09 15:05:05</td>-->
<!--          <td>马化腾</td>-->
<!--          <td>-->
<!--          	<a href="storageView.html" class="tablelink">查看详情</a>-->
<!--            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('是否确认恢复此条信息？')">恢复</a>-->
<!--          </td>-->
<!--        </tr>-->
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" id="total">1256</i>条记录，当前显示第&nbsp;<i class="blue" id="current">2&nbsp;</i>页</div>
      <ul class="paginList" id="page">
        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
        <li class="paginItem"><a href="javascript:;">1</a></li>
        <li class="paginItem current"><a href="javascript:;">2</a></li>
        <li class="paginItem"><a href="javascript:;">3</a></li>
        <li class="paginItem"><a href="javascript:;">4</a></li>
        <li class="paginItem"><a href="javascript:;">5</a></li>
        <li class="paginItem more"><a href="javascript:;">...</a></li>
        <li class="paginItem"><a href="javascript:;">10</a></li>
        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
      </ul>
    </div>
  </form>
  <!-- 提示框 -->
  <div id="tip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
    <div class="tipinfo"> <span><img src="../../images/ticon.png" /></span>
      <div class="tipright">
        <p></p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input id="subBtn" name="" type="button"  class="sure" value="确定"  />
      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose()" />
    </div>
  </div>
</div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
</html>
<script type="text/javascript">
  $(function () {
    var pageNum = 1;
    var pageSize = 5;
    addressMenuInitOfDefault($("#provinceName"), $("#cityName"), 0, 0)
    load(pageNum,pageSize);
  });

  //修改状态
  //取消
  function tipClose() {
    $("#tip").fadeOut(200);
  }

  //打开会话框
  function tipOpen(content,id,current) {
    //会话确定按钮的点击事件
    $("#subBtn").unbind("click");
    $("#subBtn").click(function () {
      var ID = 'id='+id
      axiosRequest("post", "/warehouse/updateState", ID)
              .then((res) => {
                load(current,5);
              })
      tipClose();
    })
    $(".tipright p").text(content);
    $("#tip").fadeIn(200);
  }
  function tipOpen2(content,id,current) {
    $("#subBtn").unbind("click");
    $("#subBtn").click(function () {
      var ID = 'id='+id
      axiosRequest("post", "/warehouse/recoverState", ID)
              .then((res) => {
                load(current,5)
              })
      tipClose();
    })
    $(".tipright p").text(content);
    $("#tip").fadeIn(200);

  }

  //加载仓库记录数字
  function load(pageNum,pageSize) {
    var dataArr = $("#fo").serialize()
    dataArr += "&pageNum=" + pageNum +"&pageSize="+pageSize
    axiosRequest("post", "/warehouse/pageBean", dataArr)
    .then((res) => {
      var lis = "";
      var state1 = "";
      var caozuo = "";
      for (var i = 0; i < res.data.data.length; i++) {
        if (res.data.data[i].state==1){
          state1 = "可用";
          caozuo = "          <td>\n" +
                  "          \t<a href=\"storageView.html?id="+res.data.data[i].id+"\" class=\"tablelink\">查看详情</a>\n" +
                  "            <a href=\"storageUpdate.html?id="+res.data.data[i].id+"\" class=\"tablelink\">修改</a>\n" +
                  "            <a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"tipOpen('是否确认注销此条信息？'"+","+res.data.data[i].id+","+res.data.pageNum+")\">注销</a>\n" +
                  "          </td>\n"
        }else {
          state1 = "不可用"
          caozuo = "          <td>\n" +
                  "          \t<a href=\"storageView.html?id="+res.data.data[i].id+"\" class=\"tablelink\">查看详情</a>\n" +
                  "<a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"tipOpen2('是否确认恢复此条信息？'"+","+res.data.data[i].id+","+res.data.pageNum+")\">恢复</a>\n" +
                  "          </td>\n"
        }
        var ls = "<tr>\n" +
                "          <td>"+(i+1)+"</td>\n" +
                "          <td>"+res.data.data[i].cName+"</td>\n" +
                "          <td>"+res.data.data[i].user.uName+"</td>\n" +
                "          <td>"+res.data.data[i].user.uTelephone+"</td>\n" +
                "          <td>"+res.data.data[i].province.pName+res.data.data[i].city.cName+"</td>\n" +
                "          <td>"+state1+"</td>\n" +
                "          <td>"+res.data.data[i].creationTime+"</td>\n" +
                "          <td>"+res.data.data[i].creator.uName+"</td>\n" +
                caozuo+
                "        </tr>"
        lis+=ls;
      }
      $("#body").html(lis);
      $('.tablelist tbody tr:odd').addClass('odd');

      $("#total").html(res.data.totalCount)
      $("#current").html(res.data.pageNum)
    //  页码
      var begin = res.data.pageNum-1<=1?1:res.data.pageNum-1;
      var end = res.data.pageNum+1>=res.data.totalPage?res.data.totalPage:res.data.pageNum+1;
      //限制显示页码
      var pageBegin;
      var pageEnd;
      if (res.data.totalPage<6){
        pageBegin = 1;
        pageEnd = res.data.totalPage;
      }else {
        pageBegin = res.data.pageNum-3;
        pageEnd = res.data.pageNum+2;
        if (pageBegin<1){
          pageBegin = 1;
          pageEnd = pageBegin+5;
        }
        if (pageEnd>res.data.totalPage){
          pageEnd = res.data.totalPage;
          pageBegin = pageEnd-5;
        }
      }
      var lis2 = "<li class=\"paginItem\"><a href=\"javascript:;\" onclick='load("+begin+","+pageSize+")'><span class=\"pagepre\"></span></a></li>";
      for (var i = pageBegin; i <= pageEnd; i++) {
        var li;
        if (res.data.pageNum==i){
          li = "<li class=\"paginItem current\"><a href=\"javascript:;\" onclick='load("+i+","+pageSize+")'>"+i+"</a></li>"
        }else {
          li = " <li class=\"paginItem\"><a href=\"javascript:;\" onclick='load("+i+","+pageSize+")'>"+i+"</a></li>";
        }
        lis2+=li;
      }
      lis2+="<li class=\"paginItem\"><a href=\"javascript:;\" onclick='load("+end+","+pageSize+")'><span class=\"pagenxt\"></span></a></li>"
      $("#page").html(lis2)

    })
  }
</script>